## Script (Python) "deleteObjects"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind state=state
##bind subpath=traverse_subpath
##parameters=
##title=
##


from Products.CMFPlone import PloneMessageFactory as _

req = context.REQUEST
paths=req.get('paths', [])
if (paths==[]):
    paths = req.get('paths[]')
status='failure'
message=_(u'Please select one or more items to delete.')


failure = {}
success = []

if isinstance(paths, basestring):
    paths = [paths]

for id in paths:
    try:
        context.manage_delObjects([id])
        success.append('%s (%s)' % (id, id))
    except Exception, e:
        failure[id]= e
            
if success:
    status='success'
    message = _(u'Item(s) deleted.')

if failure:
    message = _(u'${items} could not be deleted.',
                mapping={u'items' : ', '.join(failure.keys())})

context.plone_utils.addPortalMessage(message)

return state.set(status=status)
